// poj 2823

#include <iostream>
#include <vector>
#include <cmath>
#include <functional>
using namespace std;

#define INTMAX (~(1 << 31))
#define INTMIN (1 << 31)
#define N 1000006

int n, k;

typedef int Arr[N];

Arr input, maxans, minans;

// 1-based
template <typename T, int MaxIntervalLength, typename _Compare = std::less<T> >
class IntervalTree
{
	struct Node
	{
		int left;
		int right;
		T extremeVal;
	};
public:
	// @param n interval length
	// @param input get the left node's value from input array, input should be 1-based.
	void buildTree(int n, T *input)
	{
		_input = input;
		build(1, n, 1);
	}
	T queryExtremeValue(int begin, int end)
	{
		return queryExtremeValueRec(begin, end, 1);
	}

private:
	void build(int left, int right, int idx)
	{
		tree[idx].left = left;
		tree[idx].right = right;
		if (left == right)
		{
			tree[idx].extremeVal = _input[left];
		}
		else
		{
			int mid = (left + right) / 2;
			build(left, mid, 2 * idx);
			build(mid + 1, right, 2 * idx + 1);

			T lcVal = tree[2 * idx].extremeVal;
			T rcVal = tree[2 * idx + 1].extremeVal;
			tree[idx].extremeVal = (comp(lcVal, rcVal) ? lcVal : rcVal);
		}
	}
	T queryExtremeValueRec(int begin, int end, int idx)
	{
		int nleft = tree[idx].left;
		int nright = tree[idx].right;
	
		if (begin == nleft && end == nright)
			return tree[idx].extremeVal;

		int nmid = (nleft + nright) / 2;
		if (end <= nmid)
			return queryExtremeValueRec(begin, end, 2 * idx);
		else if (begin > nmid)
			return queryExtremeValueRec(begin, end, 2 * idx + 1);
		else
		{
			T lcVal = queryExtremeValueRec(begin, nmid, 2 * idx);
			T rcVal = queryExtremeValueRec(nmid + 1, end, 2 * idx + 1);
			return (comp(lcVal, rcVal) ? lcVal : rcVal);
		}
	}
private:
	Node tree[3 * MaxIntervalLength];
	T *_input;
	// comparer
	_Compare comp;
};

IntervalTree<int, 1000006, less<int> > mintree;
IntervalTree<int, 1000006, greater<int> > maxtree;

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &input[i]);
	}
	mintree.buildTree(n, input);
	maxtree.buildTree(n, input);

	for (int i = 1; i <= n - k + 1; i++)
	{
		minans[i] = mintree.queryExtremeValue(i, i + k - 1);
		maxans[i] = maxtree.queryExtremeValue(i, i + k - 1);
	}

	for (int i = 1; i <= n - k + 1; i++)
	{
		printf("%d ", minans[i]);
	}
	printf("\n");
	for (int i = 1; i <= n - k + 1; i++)
	{
		printf("%d ", maxans[i]);
	}

	system("pause");
	return 0;
}